package com.briup.corejava.day19;

import java.io.*;

/**
 * 使用数据流和文件流读取保存的基本类型数据
 * 要求读写顺序必须一致
 */
public class Test4_dr {
    public static void main(String[] args) {
        FileInputStream fis = null;
        DataInputStream dis = null;
        File file = new File("src/com/briup/corejava/day19/file/b.txt");

        try {
            fis = new FileInputStream(file);
            dis = new DataInputStream(fis);

            // 读取数据
            int i = dis.readInt();
            long l = dis.readLong();
            double v = dis.readDouble();
            float v1 = dis.readFloat();
            boolean b = dis.readBoolean();
            char c = dis.readChar();
            String s = dis.readUTF();
            System.out.println(i);
            System.out.println(l);
            System.out.println(v);
            System.out.println(v1);
            System.out.println(b);
            System.out.println(c);
            System.out.println(s);


        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if(dis != null) {
                try {
                    dis.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if(fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
